package cn.stylefeng.guns.modular.bulletin.service;

import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.bulletin.entity.Contact;
import cn.stylefeng.guns.modular.bulletin.mapper.ContactMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 客服 服务类
 */
@Service
public class ContactService extends ServiceImpl<ContactMapper,Contact> {

    /**
     * 获取客服列表
     * @param condition
     * @return
     */
    public Page<Map<String,Object>> selectByCondition(String condition) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.selectByCondition(page,condition);
    }

    public Boolean addContact(String account,String title) {
        Contact contact = new Contact();
        contact.setContactName(title);
        contact.setAccount(account);
        contact.setCreateUser(-1L);
        contact.setUpdateUser(-1L);
       return this.baseMapper.insert(contact) >0;
    }


    public List<Contact> list(String account) {
        LambdaQueryWrapper<Contact> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Contact::getAccount,account);
        lqw.orderByDesc(Contact::getContactId);
        lqw.last(" limit 5");
      return   this.baseMapper.selectList(lqw);
    }


    public void deleteContact(Long contactId) {
        this.baseMapper.deleteById(contactId);
    }





}
